package com.zqxq.lottery.entity.o2o.user;

import com.zqxq.common.utils.BigDecimalUtils;
import com.zqxq.common.utils.DispatcherUtils;
import com.zqxq.lottery.entity.po.user.UserFundsPO;
import com.zqxq.lottery.entity.vo.user.UserFundsVO;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description ：
 * @Author ： 解风
 * @Date ： 2018/03/14 16:15
 */
public class UserFundsO2O {

    public static UserFundsVO toVO(UserFundsPO po) {
        if (po == null) {
            return null;
        }
        UserFundsVO userFundsVO = new UserFundsVO();
        userFundsVO.setUserId(DispatcherUtils.parseString(po.getUser_id()));
        userFundsVO.setRealName(po.getReal_name());
        BigDecimal balanceDecimal = BigDecimalUtils.getValue(po.getBalance(),2) ;
        String balance = balanceDecimal == null ? null : balanceDecimal.toPlainString();
        userFundsVO.setBalance(balance);
        userFundsVO.setLotBean(DispatcherUtils.parseString(po.getLot_bean()));
        BigDecimal bonusDecimal = BigDecimalUtils.getValue(po.getBonus(),2) ;
        String bonus = bonusDecimal == null ? null : bonusDecimal.toPlainString();
        userFundsVO.setBonus(bonus);
        userFundsVO.setCreateTime(DispatcherUtils.parseDateTimeStr(po.getCreate_time()));
        userFundsVO.setUpdateTime(DispatcherUtils.parseDateTimeStr(po.getUpdate_time()));
        return userFundsVO;
    }

    public static UserFundsPO toPO(UserFundsVO vo) {
        if (vo == null) {
            return null;
        }
        UserFundsPO userFundsPO = new UserFundsPO();
        userFundsPO.setUser_id(DispatcherUtils.parseLong(vo.getUserId()));
        userFundsPO.setReal_name(vo.getRealName());
        userFundsPO.setBalance(BigDecimalUtils.getBigDecimal(vo.getBalance()));
        userFundsPO.setLot_bean(BigDecimalUtils.getBigDecimal(vo.getLotBean()));
        userFundsPO.setBonus(BigDecimalUtils.getBigDecimal(vo.getBonus()));
        userFundsPO.setCreate_time(DispatcherUtils.parseDateTime(vo.getCreateTime()));
        userFundsPO.setUpdate_time(DispatcherUtils.parseDateTime(vo.getUpdateTime()));
        return userFundsPO;
    }

    public static List<UserFundsVO> toVOList(List<UserFundsPO> list){
        List<UserFundsVO> result = new ArrayList();
        if(list != null && list.size() > 0){
            for (UserFundsPO po : list) {
                result.add(toVO(po));
            }
        }
        return result;
    }


}
